﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using System.Globalization;
using Shpm.App.Commons.Utils;
using Shpm.System;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Dao;



public partial class App_Commons_PhysicalRegistePopForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["PERSON_ID"]))
            {
                ViewState["PERSON_ID"] = (string)Request.QueryString["PERSON_ID"];
                txtPersonId.Text = (string)ViewState["PERSON_ID"];
                ((HtmlContainerControl)divSearch).Style.Add("display", "none");
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["PHYSICAL_ID"]))
            {
                btnBack.Enabled = false;
                ViewState["PHYSICAL_ID"] = (string)Request.QueryString["PHYSICAL_ID"];
                MultiView1.SetActiveView(View2);
                PhyscalBean dataBean = new PhyscalBean();
                dataBean.PhysicalId = int.Parse((string)this.ViewState["PHYSICAL_ID"]);
                PhyscalDao Dao = new PhyscalDao();
                SetData(Dao.Load(dataBean));
            }
            else MultiView1.SetActiveView(View1);
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PhyscalDao Dao = new PhyscalDao();
        GridView1.DataSourceID = null;
        if (ComValidator1.DoValidator())
        {
            GridView1.DataSourceID = this.ObjectDataSource1.ID;
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        
        ViewState["PHYSICAL_ID"] = row.Cells[1].Text;
        MultiView1.SetActiveView(View2);
        PhyscalBean dataBean = new PhyscalBean();
        dataBean.PhysicalId = int.Parse((string)this.ViewState["PHYSICAL_ID"]);
        PhyscalDao Dao = new PhyscalDao();
        SetData(Dao.Load(dataBean));
    }

    #region 显示数据
    //显示数据
    private void SetData(PhyscalBean dataBean)
    {
        if (dataBean != null)
        {
            ViewState["PERSON_ID"] = dataBean.PersonId.ToString();
            personID.Text = dataBean.PersonId.ToString();
            nameC.Text = dataBean.Name;
            sex.Text = GetDocData("SEX", dataBean.Sex.ToString());
            nationality.Text = GetDocData("M_PERSON.NATIONALITY", dataBean.Nationality);
            native.Text = GetDocData("M_PERSON.NATIVE", dataBean.Native);
            if (dataBean.Birthday != null) birthday.Text = (DateUtils.convertToString(dataBean.Birthday.Value)).Replace("-", "/");
            addressHome.Text = dataBean.AddressHome;
            if (dataBean.AdjustEyesightL > 0) txtAdjustEyesightL.Text = dataBean.AdjustEyesightL.ToString();
            if (dataBean.AdjustEyesightR > 0) txtAdjustEyesightR.Text = dataBean.AdjustEyesightR.ToString();
            if (dataBean.Age > 0) txtAge.Text = dataBean.Age.ToString();
            if (dataBean.AnalFistula != null) txtAnalFistula.Text = dataBean.AnalFistula.ToString();
            if (dataBean.BloodPressureBend > 0) txtBloodPressureBend.Text = dataBean.BloodPressureBend.ToString();
            if (dataBean.BloodPressureSpread > 0) txtBloodSressureSpread.Text = dataBean.BloodPressureSpread.ToString();
            if (dataBean.ChestBreath > 0) txtChestBreath.Text = dataBean.ChestBreath.ToString();
            if (dataBean.ChestSniff > 0) txtChestSniff.Text = dataBean.ChestSniff.ToString();
            if (dataBean.EyesightL > 0) txtEyesightL.Text = dataBean.EyesightL.ToString();
            if (dataBean.EyesightR > 0) txtEyesightR.Text = dataBean.EyesightR.ToString();
            if (dataBean.FamilyMedicalRecord != null) txtFamilyMedicalRecord.Text = dataBean.FamilyMedicalRecord.ToString();
            if (dataBean.Fistula != null) txtFistula.Text = dataBean.Fistula.ToString();
            if (dataBean.GripLeft > 0) txtGripLeft.Text = dataBean.GripLeft.ToString();
            if (dataBean.GripRight > 0) txtGripRight.Text = dataBean.GripRight.ToString();
            if (dataBean.HearingLeft > 0) txtHearingLeft.Text = dataBean.HearingLeft.ToString();
            if (dataBean.HearingRight > 0) txtHearingRight.Text = dataBean.HearingRight.ToString();
            if (dataBean.Height > 0) txtHeight.Text = dataBean.Height.ToString();
            if (dataBean.Liver != null) txtLiver.Text = dataBean.Liver.ToString();
            if (dataBean.Malformation != null) txtMalformation.Text = dataBean.Malformation.ToString();
            if (dataBean.Nose != null) txtNose.Text = dataBean.Nose.ToString();
            if (dataBean.OtherEye != null) txtOtherEye.Text = dataBean.OtherEye.ToString();
            if (dataBean.OtherFiveOrgans != null) txtOtherFiveOrgans.Text = dataBean.OtherFiveOrgans.ToString();
            if (dataBean.OtherInternalMedicine != null) txtOtherInternalMedicine.Text = dataBean.OtherInternalMedicine.ToString();
            if (dataBean.OtherSurgery != null) txtOtherSurgery.Text = dataBean.OtherSurgery.ToString();
            if (dataBean.PersonMedicalRecord != null) txtPersonMedicalRecord.Text = dataBean.PersonMedicalRecord.ToString();
            if (dataBean.Pudendum != null) txtPudendum.Text = dataBean.Pudendum.ToString();
            if (dataBean.Pulse > 0) txtPulse.Text = dataBean.Pulse.ToString();
            if (dataBean.Skin != null) txtSkin.Text = dataBean.Skin.ToString();
            if (dataBean.Spleen != null) txtSpleen.Text = dataBean.Spleen.ToString();
            if (dataBean.Teeth != null) txtTeeth.Text = dataBean.Teeth.ToString();
            if (dataBean.Throat != null) txtThroat.Text = dataBean.Throat.ToString();
            if (dataBean.Weight > 0) txtWeight.Text = dataBean.Weight.ToString();

            cmbColic.Text = GetDocData("T_PHYSICAL.COLIC", dataBean.Colic.ToString());
            cmbColorFeel.Text = GetDocData("T_PHYSICAL.COLORFEEL", dataBean.ColorFeel.ToString());
            cmbFlatfoot.Text = GetDocData("T_PHYSICAL.FLATFOOT", dataBean.Flatfoot.ToString());
            cmbHaemorrhoids.Text = GetDocData("T_PHYSICAL.HAEMORRHOIDS", dataBean.Haemorrhoids.ToString());
            cmbHeartRange.Text = GetDocData("T_PHYSICAL.HEARTRANGE", dataBean.HeartRange.ToString());
            cmbHeartSounds.Text = GetDocData("T_PHYSICAL.HEARTSOUNDS", dataBean.HeartSounds.ToString());
            cmbJoint.Text = GetDocData("T_PHYSICAL.JOINT", dataBean.Joint.ToString());
            cmbLimb.Text = GetDocData("T_PHYSICAL.LIMB", dataBean.Limb.ToString());
            cmbLung.Text = GetDocData("T_PHYSICAL.LUNG", dataBean.Lung.ToString());
            cmbLymph.Text = GetDocData("T_PHYSICAL.LYMPH", dataBean.Lymph.ToString());
            cmbNutrition.Text = GetDocData("T_PHYSICAL.NUTRITION", dataBean.Nutrition.ToString());
            cmbParapet.Text = GetDocData("T_PHYSICAL.PARAPET", dataBean.Parapet.ToString());
            cmbPaunch.Text = GetDocData("T_PHYSICAL.PAUNCH", dataBean.Paunch.ToString());
            cmbReflect.Text = GetDocData("T_PHYSICAL.REFLECT", dataBean.Reflect.ToString());
            cmbSmellFeel.Text = GetDocData("T_PHYSICAL.SMELLFEEL", dataBean.SmellFeel.ToString());
            cmbSpinalColumn.Text = GetDocData("T_PHYSICAL.SPINALCOLUMN", dataBean.SpinalColumn.ToString());
            cmbSpiritBend.Text = GetDocData("T_PHYSICAL.SPIRITBEND", dataBean.SpiritBend.ToString());
            cmbThyroidGland.Text = GetDocData("T_PHYSICAL.THYROIDGLAND", dataBean.ThyroidGland.ToString());
            cmbTonsil.Text = GetDocData("T_PHYSICAL.TONSIL", dataBean.Tonsil.ToString());
            cmbTrachomaLeft.Text = GetDocData("T_PHYSICAL.TRACHOMALEFT", dataBean.TrachomaLeft.ToString());
            cmbTrachomaRight.Text = GetDocData("T_PHYSICAL.TRACHOMARIGHT", dataBean.TrachomaRight.ToString());
            cmbVaricosityBend.Text = GetDocData("T_PHYSICAL.VARICOSITYBEND", dataBean.VaricosityBend.ToString());
            cmbVaricositySpread.Text = GetDocData("T_PHYSICAL.VARICOSITYSPREAD", dataBean.VaricositySpread.ToString());
        }
    }
    #endregion

    #region 取得数据字典的内容
    //取得数据字典的内容
    private string GetDocData(string str1, string str2)
    {
        CommonDictionaryBean dataBean = new CommonDictionaryBean();
        CommonDictionaryDao Dao = new CommonDictionaryDao();
        dataBean.Catalog = str1;
        dataBean.DictNo = str2;
        dataBean = Dao.Load(dataBean);
        if (dataBean != null && dataBean.Content != null) return dataBean.Content;
        else return string.Empty;
    }
    #endregion

    protected void btnBack_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink Hlink =((HyperLink)e.Row.FindControl("HyperLink1"));
            Hlink.Attributes.Add("onclick","selectPhysical(" + e.Row.Cells[1].Text + ")");
        }
    }
}
